import baseRequest from "@/utils/request";

/**
 * 重写request
 * @param config
 * @returns {Promise | Promise<unknown>}
 */
const request = function (config) {
  config.baseURL = process.env.VUE_APP_BASE_API + '/shipmentV2'
  return baseRequest(config)
}

export function getShipmentList(params = {}) {
  return request({
    url: '/getShipmentList',
    method: 'get',
    params
  })
}

/**
 * 接收货件
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function receivedShipment(data){
  return request({
    url: '/receivedShipment',
    method: 'post',
    handleError: true,
    data
  })
}


/**
 * 获取待装柜的货件
 * @returns {Promise|Promise<*>}
 */
export function getShipmentWaitCabinetBox(){
  return request({
    url: '/getShipmentWaitCabinetBox',
  })
}

/**
 * 保存上架数量
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function saveBoxLabelGoodsNum(data){
  return request({
    url: '/saveBoxLabelGoodsNum',
    method: 'put',
    data,
  })
}
/**
 * 硬件扫sku保存上架数量
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function saveHdBoxLabelGoodsNum(data){
  return request({
    url: '/saveHdBoxLabelGoodsNum',
    method: 'put',
    data,
  })
}


/**
 * 货件确认上架
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function shipmentListedBox(data){
  return request({
    url: '/shipmentListedBox',
    method: 'put',
    data,
    handleError: true,
  })
}

/**
 * 海外仓 接收货件单
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function receivedMWShipment(data){
  return request({
    url: '/receivedMWShipment',
    data,
    method: 'put',
    handleError: true,
  })
}

/**
 * 箱唛确认已分拣
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function sortedShipmentBoxLabel(data){
  return request({
    url: '/sortedShipmentBoxLabel',
    data,
    method: 'patch',
    handleError: true,
  })
}

/**
 * 货件单状态修改为已分拣
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function sortedShipment(data){
  return request({
    url: '/sortedShipment',
    data,
    method: 'put',
    handleError: true,
  })
}

/**
 * 完成分拣
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function sortedShipmentV2(id){
  return request({
    url: `/sortedShipmentV2/${id}`,
    method: 'patch',
    handleError: true,
  })
}

/**
 * 确认送仓
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function fullShipmentDelivery(data){
  return request({
    url: '/fullShipmentDelivery',
    data,
    method: 'put',
    handleError: true,
  })
}

/**
 * 确认作废
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function fullShipmentCancel(data){
  return request({
    url: '/fullShipmentCancel',
    data,
    method: 'put',
    handleError: true,
  })
}

/**
 * 导出货件单模板
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function exportShipmentBoxExcelById(id){
  return request({
    url: `/exportShipmentBoxExcelById/${id}`
  })
}

/**
 * 全部已接收
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function allReceive(id){
  return request({
    url: `/allReceive/${id}`,
    method: 'put',
    handleError: true,
  })
}

/**
 * 确认交付
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function offlineShipmentFinish(id){
  return request({
    url: `/offlineShipmentFinish/${id}`,
    method: 'put',
    handleError: true,
  })
}

/**
 * 全部已接收
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function shipmentAllSorted(id){
  return request({
    url: `/shipmentAllSorted/${id}`,
    method: 'put',
    handleError: true,
  })
}

/**
 * 删除货件单
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function deleteShipment(id){
  return request({
    url: `/deleteShipment/${id}`,
    method: 'delete',
    handleError: true,
  })
}
